<template>
  <div class="midin1">
    <h1>用户登录</h1>
    <el-form status-icon label-width="100px" class="demo-ruleForm">
      <el-form-item label="账号">
        <el-input
          type="text"
          v-model="$store.state.account"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          type="password"
          v-model="$store.state.password"
          autocomplete="off"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="login()">登录</el-button>
        <el-button @click="register()">去注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  methods: {
    async login() {
      const { data: res } = await this.$axios({
        method: "post",
        url: "/user/login",
        // get params
        data: {
          userName: this.$store.state.account,
          userPassword: this.$store.state.password,
        },
      });
      if (res.status === 0) {
        this.$router.push("/main");
      }
    },
    register() {
      this.$router.push("/register");
    },
  },
};
</script>

<style>
.midin1 {
  width: 300px;
  height: 300px;
  margin: auto;
  margin-top: 200px;
}
</style>